class Solution {
public:
    int is_prime(int n) {
        if (n == 1) return 0;
        for (int i = 2, I = sqrt(n); i <= I; i++) {
            if (n % i == 0) return 0;
        }
        return 1;
    }
    int diagonalPrime(vector<vector<int>>& nums) {
        int m = nums.size();
        int ans = 0;
        for (int i = 0; i < m; i++) {
            if (is_prime(nums[i][i])) {
                ans = max(ans, nums[i][i]);
            }
            if (is_prime(nums[i][m - i - 1])) {
                ans = max(ans, nums[i][m - i - 1]);
            }
        }
        return ans;
    }
};
